package org.openotdr.server;


import java.util.ArrayList;
import java.util.List;

import org.openotdr.server.otdr.Sr4731Parser;

import com.miyake.rest.DataColumn;
import com.miyake.rest.Value;
import com.miyake.rest.WebServiceProperty;
import com.miyake.rest.Value.SubUnit;

public class WebServicePropertyConverter {

    private Sr4731Parser parser;

    public WebServicePropertyConverter(Sr4731Parser parser) {
        this.parser = parser;
    }

    public String toXML() {
        WebServiceProperty prop = new Sr4731PropertyBuilder().getProperty();

        List<String> list = new ArrayList<String>();
        for (char point : parser.getTrace()) {
            Double d = (double)point / 1000.0;
            list.add(d.toString());
        }
        DataColumn dataColumn = new DataColumn("BSL", list.toArray(new String[0]));
        prop.getData().add(dataColumn);
        
        prop.getValues().add(new Value("DR", "Distance Range", parser.getBsc().toString(), SubUnit.None, "dB"));
        prop.getValues().add(new Value("PW", "Pulse Width", parser.getPulseWidth().toString(), SubUnit.Nano, "s"));
        prop.getValues().add(new Value("SP", "Sampling Point", parser.getSamplingPoints().toString(), SubUnit.None, "pt"));
        prop.getValues().add(new Value("IOR", "IOR", parser.getIor().toString(), SubUnit.None, "None"));
        prop.getValues().add(new Value("BSC", "BSC", parser.getBsc().toString(), SubUnit.None, "dB"));
        prop.getValues().add(new Value("WL", "Wavelength", parser.getWavelength().toString(), SubUnit.Nano, "m"));
        prop.getValues().add(new Value("AVG", "Average Time", parser.getAverage().toString(), SubUnit.None, "s"));
        return prop.toXML();
    }

}
